#coding=utf-8
'''
Created on 2017-06-20

@author: sandy
'''
import json
import logging
import ClientFactory
import zlib
import ClientBuild

class FileUpdateManager(object):
    
    def __init__(self):
        self.updateMap = {}
        pass

    def addFlagToMap(self,sid,fileName):
        if self.updateMap.get(fileName,None) == None:
            self.updateMap[fileName] = []
        li = self.updateMap[fileName]
        if sid in li:
            logging.debug(u"sid = %d has in fileName = %s updateMap",sid,fileName)
        else:
            li.append(sid)
            
    def updateFile(self,cfgname,content):
        serverList = self.updateMap.get(cfgname,None)
        if serverList == None:
            logging.debug(u"%s no server need update",cfgname)
        else:
            for i in serverList:
                client = ClientFactory.instance.getClientSrvBySid(i)
                if client:
                    strContent = zlib.compress(content)
                    client.sendPacket(ClientBuild.sendConfig(cfgname,strContent))
                else:
                    logging.debug(u"sid = %d server is not exit",i)
        pass

instance = FileUpdateManager()